package cn.meibang.common.beauty.provider.dao;

import cn.apestar.core.database.BaseMapper;
import cn.meibang.common.beauty.provider.domain.BeautyConsultationOrderUserProduct;
import cn.meibang.common.beauty.provider.request.ListRecommendHistoryRequest;
import cn.meibang.common.beauty.provider.response.HistoryRecommendResponse;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface BeautyConsultationOrderUserProductMapper extends BaseMapper {

    @Delete({"delete from beauty_consultation_order_user_product" , "where id = #{id,jdbcType=BIGINT}"})
    int deleteByPrimaryKey(Long id);

    @Insert({"insert into beauty_consultation_order_user_product (id, tag, " , "user_id, openid, order_id, recommend_type, " , "product_id, product_name, " ,
            "consultant_id, consultant_name, " , "price, create_by, " , "create_date, update_by, " , "update_date, remarks, " ,
            "del_flag, institution_id)" , "values (#{id,jdbcType=BIGINT}, #{tag,jdbcType=VARCHAR}, " ,
            "#{userId,jdbcType=BIGINT}, #{openid}, #{orderId,jdbcType=BIGINT}, #{recommendType,jdbcType=VARCHAR}, " ,
            "#{productId,jdbcType=BIGINT}, #{productName,jdbcType=VARCHAR}, " ,
            "#{consultantId,jdbcType=BIGINT}, #{consultantName,jdbcType=VARCHAR}, " , "#{price,jdbcType=DECIMAL}, #{createBy,jdbcType=BIGINT}, " ,
            "#{createDate,jdbcType=TIMESTAMP}, #{updateBy,jdbcType=BIGINT}, " , "#{updateDate,jdbcType=TIMESTAMP}, #{remarks,jdbcType=VARCHAR}, " ,
            "#{delFlag,jdbcType=CHAR}, #{institutionId,jdbcType=BIGINT})"})
    int insert(BeautyConsultationOrderUserProduct record);

    @InsertProvider(type = BeautyConsultationOrderUserProductSqlProvider.class, method = "insertSelective")
    int insertSelective(BeautyConsultationOrderUserProduct record);

    @Select({"select" , "id, tag, user_id, openid, order_id, recommend_type, product_id, product_name, consultant_id, " ,
            "consultant_name, price, create_by, create_date, update_by, update_date, remarks, " , "del_flag, institution_id" ,
            "from beauty_consultation_order_user_product" , "where id = #{id,jdbcType=BIGINT}"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true) ,
            @Result(column = "tag", property = "tag", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "openid", property = "openid", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "order_id", property = "orderId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "recommend_type", property = "recommendType", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "product_id", property = "productId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "product_name", property = "productName", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "consultant_id", property = "consultantId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "consultant_name", property = "consultantName", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL) ,
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP) ,
            @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.TIMESTAMP) ,
            @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.CHAR) ,
            @Result(column = "institution_id", property = "institutionId", jdbcType = JdbcType.BIGINT)})
    BeautyConsultationOrderUserProduct selectByPrimaryKey(Long id);

    @Select({"select" , "id, tag, user_id, openid, order_id, recommend_type, product_id, product_name, consultant_id, " ,
            "consultant_name, price, create_by, create_date, update_by, update_date, remarks, " , "del_flag, institution_id" ,
            "from beauty_consultation_order_user_product" , "where tag = #{tag} and del_flag = '1'"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true) ,
            @Result(column = "tag", property = "tag", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "openid", property = "openid", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "order_id", property = "orderId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "recommend_type", property = "recommendType", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "product_id", property = "productId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "product_name", property = "productName", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "consultant_id", property = "consultantId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "consultant_name", property = "consultantName", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL) ,
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP) ,
            @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.TIMESTAMP) ,
            @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.CHAR) ,
            @Result(column = "institution_id", property = "institutionId", jdbcType = JdbcType.BIGINT)})
    List<BeautyConsultationOrderUserProduct> selectByTag(@Param("tag") String tag);

    @Select({"select" , "id, tag, user_id, openid, order_id, recommend_type, product_id, product_name, consultant_id, " ,
            "consultant_name, price, create_by, create_date, update_by, update_date, remarks, " , "del_flag, institution_id" ,
            "from beauty_consultation_order_user_product" , "where user_id = #{userId} and del_flag = '1'" , "order by id desc" ,
            "limit #{offset}, #{size}"})
    @Results({@Result(column = "id", property = "id", jdbcType = JdbcType.BIGINT, id = true) ,
            @Result(column = "tag", property = "tag", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "user_id", property = "userId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "openid", property = "openid", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "order_id", property = "orderId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "recommend_type", property = "recommendType", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "product_id", property = "productId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "product_name", property = "productName", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "consultant_id", property = "consultantId", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "consultant_name", property = "consultantName", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "price", property = "price", jdbcType = JdbcType.DECIMAL) ,
            @Result(column = "create_by", property = "createBy", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "create_date", property = "createDate", jdbcType = JdbcType.TIMESTAMP) ,
            @Result(column = "update_by", property = "updateBy", jdbcType = JdbcType.BIGINT) ,
            @Result(column = "update_date", property = "updateDate", jdbcType = JdbcType.TIMESTAMP) ,
            @Result(column = "remarks", property = "remarks", jdbcType = JdbcType.VARCHAR) ,
            @Result(column = "del_flag", property = "delFlag", jdbcType = JdbcType.CHAR) ,
            @Result(column = "institution_id", property = "institutionId", jdbcType = JdbcType.BIGINT)})
    List<BeautyConsultationOrderUserProduct> selectPageByUserId(@Param("offset") int offset, @Param("size") int size, @Param("userId") Long userId);

    @SelectProvider(type = BeautyConsultationOrderUserProductSqlProvider.class, method = "listProduct")
    @ResultType(value = HistoryRecommendResponse.class)
    List<HistoryRecommendResponse> listProduct(ListRecommendHistoryRequest request);

    @UpdateProvider(type = BeautyConsultationOrderUserProductSqlProvider.class, method = "updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(BeautyConsultationOrderUserProduct record);

    @Update({"update beauty_consultation_order_user_product" , "set tag = #{tag,jdbcType=VARCHAR}," ,
            "user_id = #{userId,jdbcType=BIGINT}," ,
            "openid = #{openid,jdbcType=VARCHAR}," ,
            "order_id = #{orderId,jdbcType=BIGINT}," , "recommend_type = #{recommendType,jdbcType=VARCHAR}," ,
            "product_id = #{productId,jdbcType=BIGINT}," , "product_name = #{productName,jdbcType=VARCHAR}," ,
            "consultant_id = #{consultantId,jdbcType=BIGINT}," , "consultant_name = #{consultantName,jdbcType=VARCHAR}," ,
            "price = #{price,jdbcType=DECIMAL}," , "create_by = #{createBy,jdbcType=BIGINT}," , "create_date = #{createDate,jdbcType=TIMESTAMP}," ,
            "update_by = #{updateBy,jdbcType=BIGINT}," , "update_date = #{updateDate,jdbcType=TIMESTAMP}," ,
            "remarks = #{remarks,jdbcType=VARCHAR}," , "del_flag = #{delFlag,jdbcType=CHAR}," , "institution_id = #{institutionId,jdbcType=BIGINT}" ,
            "where id = #{id,jdbcType=BIGINT}"})
    int updateByPrimaryKey(BeautyConsultationOrderUserProduct record);
}